package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

public class IterationSkill extends BaseSkill {

    LivingEntity lasttarget = null;
    int attacktimes = 0;

    public IterationSkill(int level) {
        super(level);
    }

    public IterationSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public IterationSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMaxlevel(10);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("对同一目标的伤害每次额外增加0.5倍，最高不超过（（技能等级+2）/2倍）。");
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean onAttack(MobEntity attacker, LivingEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        attacktimes += 1;
        if (target == lasttarget) {
            if (attacktimes < getSkillLevel() + 1) {
                amount.setValue(amount.getValue() * (attacktimes + 1) / 2);
            } else {
                amount.setValue(amount.getValue() * (getSkillLevel() + 2) / 2);
            }

        } else {
            attacktimes = 1;
        }
        lasttarget = target;
        return true;
    }
}
